package org.domain.projeto.util;

import java.io.Serializable;
import java.util.MissingResourceException;

import org.jboss.seam.annotations.In;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.core.SeamResourceBundle;
import org.jboss.seam.faces.FacesMessages;
import org.jboss.seam.international.StatusMessage.Severity;

@Name("mensagem")
public class Mensagem implements Serializable {

	private static final long serialVersionUID = 1405964106886914630L;
	
	@In(required = true, create = true)
	private FacesMessages facesMessages;
	
	@In(required = true, create = true)
	private SeamResourceBundle resourceBundle;
	
	public void info(String chave) {
		try {
			String msg = resourceBundle.getString(chave);
			facesMessages.add(Severity.INFO, msg);
		} catch (MissingResourceException e) {
			facesMessages.add(Severity.INFO, chave);
		}
	}
	
	public void info(String chave, Object... params) {
		try {
			String msg = resourceBundle.getString(chave);
			facesMessages.add(Severity.INFO, msg, params);
		} catch (MissingResourceException e) {
			facesMessages.add(Severity.INFO, chave);
		}
	}

	public void erro(String chave) {
		try {
			String msg = resourceBundle.getString(chave);
			facesMessages.add(Severity.ERROR, msg);
		} catch (MissingResourceException e) {
			facesMessages.add(Severity.ERROR, chave);
		}
	}
	
	public void erro(String chave, Object...params) {
		try {
			String msg = resourceBundle.getString(chave);
			facesMessages.add(Severity.ERROR, msg, params);
		} catch (MissingResourceException e) {
			facesMessages.add(Severity.ERROR, chave);
		}
	}

	public void alerta(String chave) {
		try {
			String msg = resourceBundle.getString(chave);
			facesMessages.add(Severity.WARN, msg);
		} catch (MissingResourceException e) {
			facesMessages.add(Severity.WARN, chave);
		}
	}

	public void alerta(String chave, Object... params) {
		try {
			String msg = resourceBundle.getString(chave);
			facesMessages.add(Severity.WARN, msg, params);
		} catch (MissingResourceException e) {
			facesMessages.add(Severity.WARN, chave);
		}
	}
}